<script type="text/javascript"> 
function ckCustomer(name){
    if( jQuery.trim(name) != '' && name.length > 2){
        $.ajax({
          url: '<?php echo $this->createUrl('order/ckcustomer');?>?name='+name,
          success: function(data) {
            if(data == 1){
                var see =confirm('ชื่อลูกค้าชื่อซ้ำ  จะดูข้อมูลเพิ่มไหมครับ')
                if(see){
                     window.location.assign('<?php echo $this->createUrl('order/admin',array('Order_page'=>1,'ajax'=>'order-grid'));?>&Order[customer]='+name);

                }
            }
          }
        });
    }
}

function CKtrans(){

    if($('#Order_bank').val() != '' && jQuery.trim($('#Order_date_trans').val()) != '' ){
        $.ajax({
          url: '<?php echo $this->createUrl('order/cktrans');?>?time='+$('#Order_date_trans').val()+'&bank='+$('#Order_bank').val(),
          success: function(data) {
             data=jQuery.parseJSON(data);

            if(data.n == 1){
                var see =confirm('การโอนเงินนี้ได้ถูกบัฯทึกไว้แล้วดูรายละเอียดหรือไม่'  )
                if(see){
                     window.location.assign('<?php echo $this->createUrl('order/admin',array('Order_page'=>1,'ajax'=>'order-grid'));?>&Order[date_trans]='+data.time+'&Order[bank]='+data.bank);
                }
            }
          }
        });
    }


}
</script>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'order-form',
    'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>
    <div class="row">
   		<?php echo $form->labelEx($model,'sender'); ?>
        <select name="Order[sender]" id="Order_sender">
        <?php

            $liastDealers = Dealers::model()->findAll()?>
            <option value="" >เลือก</option>
        <?php foreach($liastDealers as $key => $val){
            $select='';
            if($model->attributes['sender'] == null && $val['id'] == 2){
                    $select = 'selected="selected"';
            }elseif($val['id'] == $model->attributes['sender']){
                    $select = 'selected="selected"';
            }
            echo '<option '.$select.'  value="'.$val['id'].'" >'.$val['name'].'</option>';
        }?>
        </select>
   		<?php echo $form->error($model,'sender'); ?>
   	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'customer'); ?>
		<?php echo $form->textField($model,'customer',array('size'=>60,'maxlength'=>255,'onblur'=>'ckCustomer(this.value)')); ?>
		<div class="errorMessage" id="ckcustomer"></div>
        <?php echo $form->error($model,'customer'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'address'); ?>
		<?php echo $form->textArea($model,'address',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'address'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'products'); ?>
		<?php echo $form->textArea($model,'products',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'products'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'transferred'); ?>
		<?php echo $form->textField($model,'transferred',array('size'=>60,'maxlength'=>255)); ?>
		<p class="hint">ตัวอย่าง 1600</p>
		<?php echo $form->error($model,'transferred'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'bank'); ?>
		<?php
//            $this->widget('CAutoComplete', array(
//			'model'=>$model,
//			'attribute'=>'bank',
//			'url'=>array('bank'),
//			'multiple'=>false,
//			'htmlOptions'=>array('size'=>50),
//
//		));
        ?>
		<?php echo $form->DropDownList($model, 'bank',
			array('empty' => 'เลือก','scb' => 'scb', 'k-bank' => 'k-bank', 'bbl' => 'bbl', 'อื่นๆ' => 'อื่นๆ' ),
            array('onChange'=>'CKtrans()')
		); ?>
		<p class="hint">ตัวอย่าง ไทยพาณิชย์  3612220109</p>
		<?php echo $form->error($model,'bank'); ?>
	</div>

	<div class="row">
    <?php echo $form->labelEx($model,'date_trans'); ?>
    <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
			'model'=>$model,
			'attribute'=>'date_trans',

        // additional javascript options for the date picker plugin
        'options'=>array(
            'showAnim'=>'fold',
            'dateFormat'=>'dd/mm/yy 00:00',
        ),
                      
        'htmlOptions'=>array(
            'style'=>'height:20px;',
            'onblur'=>'setTimeout(function(){CKtrans();},500)',
            'autocomplete'=>'off'
        ),
    ));
    ?>
    <?php echo $form->error($model,'date_trans'); ?>
    </div>
	<div class="row">
		<?php echo $form->labelEx($model,'status'); ?>
		<?php echo $form->DropDownList($model, 'status',
			array(
                'รอเช็คโอนเงิน' => 'รอเช็คโอนเงิน',
                'รอจัดของ'=>'รอจัดของ',
                'รอส่งของ' => 'รอส่งของ',
                'ส่งแล้ว' => 'ส่งแล้ว' ),
			array('empty' => 'เลือก')
		); ?>
		<?php echo $form->error($model,'status'); ?>
	</div>

    <div class="row">
        <?php echo $form->labelEx($model,'ems'); ?>
        <?php echo $form->textField($model,'ems',array('size'=>60,'maxlength'=>255)); ?>
        <?php echo $form->error($model,'ems'); ?>
        <p class="hint">ตัวอย่าง EI701256341TH หรือ เลขที่ใบส่งของ หรือ อื่นๆ</p>
    </div>

	<div class="row">
		<?php echo $form->labelEx($model,'note'); ?>
		<?php echo $form->textArea($model,'note',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'note'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>


</div><!-- form -->